package com.atguigu.tingshu.common.config.threadPool;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 线程池配置类
 * @author Haoran Sun
 * @since 2024/08/23
 */

@Configuration
public class TingshuThreadPool {

    /**
     * 线程池对象初始化
     * @return 线程池对象
     */
    @Bean("threadPoolExecutor")
    public ThreadPoolExecutor threadPoolExecutor() {
        return new ThreadPoolExecutor(
                Runtime.getRuntime().availableProcessors(),
                Runtime.getRuntime().availableProcessors() * 2,
                60,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(12),
                new ThreadPoolExecutor.AbortPolicy()
        );
    }


}
